package com.fmsz.xmly.adapters.download;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fmsz.xmly.R;
import com.fmsz.xmly.entitys.download.RecommendEntity;
import com.squareup.picasso.Picasso;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2016/12/13.
 */

public class RecommendAdapter extends RecyclerView.Adapter<RecommendAdapter.MyViewHodler> {

    private Context context;
    private List<RecommendEntity.SubEntity> list;

    public RecommendAdapter(Context context, List<RecommendEntity.SubEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public MyViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHodler(LayoutInflater.from(context).inflate(R.layout.item_hot_recommend, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHodler holder, int position) {
        Picasso.with(context).load(list.get(position).getAlbumCoverUrl290()).into(holder.image_hotrecommend);
        holder.title_hotrecommend.setText(list.get(position).getTitle());
        holder.intro.setText(list.get(position).getIntro());
        String counts = list.get(position).getPlaysCounts();
        double i = Integer.parseInt(counts)/ 10000;
        BigDecimal bd = new BigDecimal(i);
        bd = bd.setScale(1, BigDecimal.ROUND_DOWN);//BigDecimal.ROUND_HALF_UP 是4舍5入，BigDecimal.ROUND_DOWN是舍去，BigDecimal.ROUND_FLOOR是向上取整
        holder.play_count.setText(" " + bd+ "万");
        holder.tracks.setText(" " + list.get(position).getTracks() + "集");

    }


    public static class MyViewHodler extends RecyclerView.ViewHolder {
        private ImageView image_hotrecommend;
        private TextView title_hotrecommend;
        private TextView intro;
        private TextView play_count;
        private TextView tracks;

        public MyViewHodler(View itemView) {
            super(itemView);
            image_hotrecommend = (ImageView) itemView.findViewById(R.id.image_hotrecommend);
            title_hotrecommend = (TextView) itemView.findViewById(R.id.title_hotrecommend);
            intro = (TextView) itemView.findViewById(R.id.intro);
            play_count = (TextView) itemView.findViewById(R.id.play_count);
            tracks = (TextView) itemView.findViewById(R.id.tracks);
        }
    }
}
